package com.zzb.springcloud.controller;

import com.zzb.springcloud.common.CommonResult;
import com.zzb.springcloud.entity.Payment;
import com.zzb.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 支付业务数据交互
 * @CreateTime 2021/4/16 0016 10:57
 * @Author 不浪小生
 */
@Slf4j
@RestController
public class PaymentCtr {

    @Autowired
    private PaymentService paymentService;
    @Value("${server.port}")
    private String hostPort;

    @PostMapping("/payment/save")
    public CommonResult save(@RequestBody Payment payment) {
        log.info("支付参数：" + payment);
        int count = paymentService.create(payment);
        if (count > 0) {
            return new CommonResult(200, "支付成功", count);
        }

        return new CommonResult(500, "支付失败");
    }
    @GetMapping("/payment/getPayment/{id}")
    public CommonResult getPayment(@PathVariable("id") Long id) {
        Payment result = paymentService.getById(id);
        if (result ==null) {
            return new CommonResult(404, "查询失败");
        }
        log.info("获取查询数据:" + result);
        return new CommonResult(200, "获取数据,请求端口:" + hostPort, result);
    }

    @GetMapping("/payment/loadbanlance")
    public CommonResult loadbanlance() {
        return new CommonResult(200, "获取数据,请求端口:" + hostPort, null);
    }

}
